<template>
  <div class="box">
    <div class="prod-title flex-a flex-b">
      <div class="flex-a">
        <div class="basic">普通项目</div>
        <el-button type="warning" class="btn-plain" @click="back">返回上一页</el-button>
      </div>
      <div>
        <el-button type="warning" style="padding:12px 40px" class="btn" @click="killOrder">撤单</el-button>
      </div>
    </div>
    <el-table v-loading="loading" :data="orderspcList">
      <el-table-column label="消费项目" align="center" prop="orderNo" />
      <el-table-column label="零售价" align="center" prop="discount" />
      <el-table-column label="折扣率" align="center" prop="num" />
      <el-table-column label="折后价" align="center" prop="actPrice" />
      <el-table-column label="数量" align="center" prop="state" />
      <el-table-column label="小计" align="center" prop="cashier" />
      <el-table-column label="实收金额" align="center" prop="cashier" />
      <el-table-column label="销售员" align="center" prop="cashier" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="returnGoods(scope.row)"
            v-hasPermi="['pet:orderspc:remove']">退货</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="text-align: center;">
      <el-button type="warning" style="padding:12px 40px;margin: 20px auto 0;" class="btn" @click="killOrder">撤单</el-button>
    </div>
    <!-- 退货退款对话框 -->
    <el-dialog title="退货退款" :visible.sync="open" width="500px" class="center" append-to-body>
      <el-form ref="form" :model="form" class="input" :rules="rules" label-width="80px">
        <el-form-item label="退货数量" prop="num">
          <el-input v-model="form.num" placeholder="请输入退货数量（可退货数量 1.00）" />
        </el-form-item>
        <el-form-item label="退款金额" prop="cashier">
          <span>微信-￥1.00</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" class="btn" style="padding: 12px 40px;" @click="submitForm">确认退货退款</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderspc, getOrderspc, delOrderspc, addOrderspc, updateOrderspc } from "@/api/pet/orderspc";

export default {
  name: "Orderspc",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单货品详情表格数据
      orderspcList: [],
      // 是否显示弹出层
      open: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        type: null,
        prjNo: null,
        retPrice: null,
        discount: null,
        num: null,
        actPrice: null,
        state: null,
        cashier: null,
        updateUser: null,
        createUser: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单货品详情列表 */
    getList() {
      this.loading = true;
      listOrderspc(this.queryParams).then(response => {
        this.orderspcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 返回上一页
    back() {
      this.$router.push({ path: '/business/order' })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        type: null,
        prjNo: null,
        retPrice: null,
        discount: null,
        num: null,
        actPrice: null,
        state: null,
        cashier: null,
        updateUser: null,
        updateTime: null,
        createUser: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单货品详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderspc(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单货品详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrderspc(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderspc(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //撤单
    killOrder() {

    },
    //退货
    returnGoods(row) {

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pet/orderspc/export', {
        ...this.queryParams
      }, `orderspc_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped lang="scss">
.box {
  .prod-title {
    .basic {
      font-size: 18px;
      color: #333336;
      font-weight: 700;
      margin-right: 30px;

      span {
        color: #409eff;
        font-size: 12px;
        font-weight: normal;
        margin: 0 20px 0 5px;
      }
    }
  }
}
</style>
